package com.xzzz.irda.guardcat.server.repos.elasticsearch.pojo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.xzzz.expand.es.core.annotation.EsId;
import com.xzzz.expand.es.core.annotation.EsIndex;
import lombok.Data;

import java.lang.reflect.Field;


/**
 * ES 对扁平化数据的处理快速
 *
 * @author xzzz
 */
@Data
@EsIndex(name = "index_guardcat_memory")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class JmmInfoEsEntity {

    @EsId
    private String id;
    private String machineId;
    private String appName;
    private String gmt;

    /**
     * 堆内存
     */
    private Long hi;
    private Long hm;
    private Long hc;
    private Long hu;

    /**
     * 非堆内存
     */
    private Long nhi;
    private Long nhm;
    private Long nhc;
    private Long nhu;

    /**
     * 元空间内存
     */
    private Long mi;
    private Long mm;
    private Long mc;
    private Long mu;

    /**
     * 新生代
     */
    private Long ei;
    private Long em;
    private Long ec;
    private Long eu;

    /**
     * 幸存代
     */
    private Long si;
    private Long sm;
    private Long sc;
    private Long su;

    /**
     * 老年代
     */
    private Long oi;
    private Long om;
    private Long oc;
    private Long ou;

    /**
     * JIT 编译代码缓存区内存
     */
    private Long cci;
    private Long ccm;
    private Long ccc;
    private Long ccu;

    /**
     * 类压缩数据区
     */
    private Long ccsi;
    private Long ccsm;
    private Long ccsc;
    private Long ccsu;

    /**
     * 输出 ES 索引 mapping, 几个非指标字段需要改类型
     *
     * @param args
     */
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder(
                "{\n" +
                        "  \"mappings\": {\n" +
                        "    \"dynamic\": \"strict\",\n" +
                        "    \"properties\": {");

        for (Field field : JmmInfoEsEntity.class.getDeclaredFields()) {
            sb.append("\"").append(field.getName()).append("\"").append(":{")
                    .append("\"type\":\"long\"")
                    .append("},\n");
        }

        sb.append("    }\n" +
                "  }\n" +
                "}");
        System.out.println(sb.toString());
    }
}
